<?php

class Application_Model_Account
{
    const DEFAULT_MAX_NEWNITS = 20;
    public $id = 0;
    public $email = '';
    public $openid = '';
    public $lastUpdateTime;
    public $tokenCount;
    public $classCount;
    public $firstName;
    public $lastName;
    public $country;
    public $language;
    public $max_newnits = 20;

    public static function fromTableRow($row)
    {
        $result = new Application_Model_Account();
        $result->id = (int)$row['account_id'];
        $result->email = $row['email'];
        $result->openid = $row['openid'];
        $result->firstName = $row['firstName'];
        $result->lastName = $row['lastName'];
        $result->country = $row['country'];
        $result->language = $row['language'];
        $result->lastUpdateTime = new Zend_Date((int)$row['last_update_time'], Zend_Date::TIMESTAMP);
        $result->tokenCount = (int)$row['token_count'];
        $result->classCount = array('pos' => (int)$row['token_pos_count'], 'neg' => (int)$row['token_neg_count']);
        $result->max_newnits = (int)$row['max_newnits'];
        return $result;
    }

    public function __tostring()
    {
        $result = "Id : " . $this->id . ";\n";
        $result .= "E-mail : " . $this->email . ";\n";
        $result .= "OpenId : " . $this->openid . ";\n";
        return $result;
    }

    public function __destruct()
    {
        unset($this->id);
        unset($this->email);
        unset($this->openid);
    }
}

